package com.game;

import java.util.Vector;
import java.util.Random;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Point;

public class PowerUpManager {
	public Vector<PowerUp> powerUps;
	
	Context mContext;
	BackgroundMirror mBackgroundMirror;
	PlayScene mSceneRef;
	private long oldTime;
	
	
	PowerUpManager( Context context, BackgroundMirror bgMirror , PlayScene threadRef)
	{
		powerUps = new Vector<PowerUp>();		
		mContext = context;
		mBackgroundMirror = bgMirror;
		mSceneRef =threadRef;
	}
	
	public void Reset()
	{
		powerUps.clear();
	}
	
	public void Update()
	{
		for( PowerUp pUp : powerUps)
		{
			pUp.Update();
		}
		CheckIfAddNewPUP();
	}
	
	private void CheckIfAddNewPUP() {
		
		long curTime = System.currentTimeMillis();		

		long elapsed = curTime - oldTime;
		if( elapsed >= 3000)
		{
			Random generator = new Random();
			
			if(generator.nextInt(50) < 10)
			{
				CreateNewPUP();
			}
			oldTime = curTime;
		}		
	}

	private void CreateNewPUP() {
		//Change for different types of UPUs
		Random rnd = new Random();
		switch (rnd.nextInt(2)) {
		case 0:
			LaserDupPowerUp auxLPUP= new LaserDupPowerUp(mContext, mBackgroundMirror, new Point(100,100),
					R.drawable.powerup, R.drawable.dimmpowerup, R.drawable.dimmpowerup2,mSceneRef);
			powerUps.add(auxLPUP);
			break;
		case 1:
			StopBallPowerUp auxBPUP= new StopBallPowerUp(mContext, mBackgroundMirror, new Point(100,100),
					R.drawable.stopballpup, R.drawable.stopballpupd1, R.drawable.stopballpupd2,mSceneRef);
			powerUps.add(auxBPUP);
			break;
			
		default:
			break;
		}
				
		
	}

	public void Draw(Canvas canvas)
	{
		for( PowerUp pUp : powerUps)
		{
			pUp.Draw(canvas);
		}
	}
	
	
	
}
